package com.example.bluetoothdemo.util;

import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.view.View;
import android.view.Window;
import android.widget.Toast;

public class MyUtils {

    /**
     * Toast简化 (封装Toast)
     *
     * @param context 上下文 (Activity中直接getContext获取) (直接使用Toast这个参数可以用xxxActivity.this,这里应该也可以用)
     * @param text    提示内容
     */
    public static void simpleToast(Context context, String text) {
        Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
    }

    public static void changeStatusColor(Context context, int colorId) {
        Activity activity = (Activity) context;
        Window window = activity.getWindow();
        //window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        //window.getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        window.setStatusBarColor(activity.getResources().getColor(colorId));

    }

    /**
     * 更改系统状态栏的颜色 true->黑 false->白
     *
     * @param context 上下文 (Activity中直接getContext获取)
     * @param setDark true->黑 false->白
     */
    public static void changeStatusIconColor(Context context, boolean setDark) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            View decorView = ((Activity) context).getWindow().getDecorView();
            if (decorView != null) {
                int vis = decorView.getSystemUiVisibility();
                if (setDark) {
                    vis |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
                } else {
                    vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
                }
                decorView.setSystemUiVisibility(vis);
            }
        }
    }

    public static void myHandler(Runnable r, int delay) {
        new Handler().postDelayed(r, delay);
    }

}
